package leetcode.code2411;

public class Solution {
	public int[] smallestSubarrays(int[] nums) {
		int[] ans = new int[nums.length];
		for (int i = nums.length - 1, max = 0, r = nums.length - 1; i >= 0; i--) {
			max |= nums[i];
			int l = i;
			int cur = 0;
			while (l <= r) {
				int m = ((r - l) >> 1) + l;
				int sum = 0;
				for (int j = i; j <= m; j++) {
					sum |= nums[j];
				}
				if (sum >= max) {
					cur = m;
					r = m - 1;
				} else {
					l = m + 1;
				}
			}
			ans[i] = cur - i + 1;
			r = cur;
		}
		return ans;
	}
}
